﻿/*========================== 
 * @author 郑金泉
 * @desc SQL CONTANIS 条件类
 * ========================= */
using System;
using System.Collections.Generic;
using System.Text;

using Obsidian.Edm;

namespace Obsidian.Data.Sql
{
    public class ContanisCondition : SqlCondition, ISqlCondition
    {

        private ModelField _modelField;
        private string _matchingString = null;

        public ContanisCondition(ModelField field, string matchingString)
        {
            this.Init(Sql.LogicalOperator.AND, field, matchingString);
        }

        public ContanisCondition(LogicalOperator logicalOperator, ModelField field, string matchingString)
        {
            this.Init(logicalOperator, field, matchingString);
        }

        private void Init(LogicalOperator logicalOperator, ModelField field, string matchingString)
        {
            this.LogicalOperator = logicalOperator;
            this._modelField = field;
            this._matchingString = matchingString;
        }


        public string BuildSqlText()
        {
            StringBuilder sb = new StringBuilder();
            sb.Append(" CONTAINS (")
                .Append(this._modelField.GetDbField().TablePrefixName)
                .Append(" ,'")
                .Append(this._matchingString)
                .Append("')");
            return sb.ToString();
        }
    }
}
